package server;

import java.io.InputStream;
import java.util.Properties;

import exceptions.LoadConfigException;

public class Configuration {
	private String url;
	private String driver;
	private String username;
	private String password;
	
	private int initialSize;
	private int maxActive;
	private int maxIdle;
	private int maxWait;
	private String validationQuery;
	
	public Configuration() {
	}
	
	public static Configuration configure() throws LoadConfigException{
		InputStream in = Configuration.class.getResourceAsStream("/serverConfig.properties");
		Properties props = new Properties();
		try {
			props.load(in);
			in.close();
		} catch (Exception e) {
			e.printStackTrace();
			throw new LoadConfigException(e);
		}
		
		Configuration cfg= new Configuration();
		cfg.setUrl(props.getProperty("url"));
		cfg.setDriver(props.getProperty("driver"));
		cfg.setUsername(props.getProperty("username"));
		cfg.setPassword(props.getProperty("password"));
		
		cfg.setInitialSize(Integer.parseInt(props.getProperty("initialSize")));
		cfg.setMaxActive(Integer.parseInt(props.getProperty("maxActive")));
		cfg.setMaxIdle(Integer.parseInt(props.getProperty("maxIdle")));
		cfg.setMaxWait(Integer.parseInt(props.getProperty("maxWait")));
		cfg.setValidationQuery(props.getProperty("validationQuery"));
		
		return cfg;
	}

	public String getDriver() {
		return driver;
	}

	public int getInitialSize() {
		return initialSize;
	}

	public int getMaxActive() {
		return maxActive;
	}

	public int getMaxIdle() {
		return maxIdle;
	}

	public int getMaxWait() {
		return maxWait;
	}

	public String getPassword() {
		return password;
	}

	public String getUrl() {
		return url;
	}

	public String getUsername() {
		return username;
	}

	public String getValidationQuery() {
		return validationQuery;
	}

	public void setDriver(String driver) {
		this.driver = driver;
	}

	public void setInitialSize(int initialSize) {
		this.initialSize = initialSize;
	}

	public void setMaxActive(int maxActive) {
		this.maxActive = maxActive;
	}

	public void setMaxIdle(int maxIdle) {
		this.maxIdle = maxIdle;
	}

	public void setMaxWait(int maxWait) {
		this.maxWait = maxWait;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public void setUrl(String url) {
		this.url = url;
	}

	public void setUsername(String username) {
		this.username = username;
	}

	public void setValidationQuery(String validationQuery) {
		this.validationQuery = validationQuery;
	}
	
	
}
